#include <iostream>
#include <queue>
#include <vector>
using namespace std;

const int kMaxN = (int)1e5 + 10;

struct vertex {
  vector<int> edges;
} graph[kMaxN];
bool visited[kMaxN] = {false};

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int n, m;

  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;

    cin >> u >> v;
    graph[u].edges.emplace_back(v);
    graph[v].edges.emplace_back(u);
  }

  priority_queue<int> p_q;

  for (p_q.push(-1), visited[1] = true; !p_q.empty();) {
    int now = -p_q.top();

    cout << now << ' ';
    p_q.pop();
    for (int next : graph[now].edges) {
      if (!visited[next]) {
        visited[next] = true;
        p_q.push(-next);
      }
    }
  }
  cout << endl;
  return 0;
}